from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        text = Tex(r"\text{(张1000)已知微分方程}$y'+y=e^{\sin x},$\text{证明方程存在唯一的以}$2\pi $\text{为周期的解}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
        text1 = Tex(r"\text{(2018年数一)已知微分方程}$y'+y=f\left( x\right) ,$\text{其中}$f\left( x\right)  $\text{是R上的连续函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
        text2 = Tex(r"\text{1.若}$f\left( x\right) =x,$\text{求微分方程的通解}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-23,15,0])
        text3 = Tex(r"\text{2.若}$f\left( x\right) $\text{是周期为T的函数,}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,10,0])
        text4 = Tex(r"\text{证明微分方程有通解与其对应,且该通解也为周期函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-11,5,0])
        self.play(Write(text),self.camera.frame.animate.scale(1))
        self.wait()
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)

        text1 = Tex(r"$y\left( x\right) =e^{-x}\left[ \int e^{\sin x}\cdot e^{x}dx+C\right] $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,10,0])
        self.play(Write(text1),self.camera.frame.animate.scale(1).shift(DOWN*5))
        text2 = Tex(r"$y\left( x\right) =e^{-x}\left[ \int ^{x}_{0}e^{\sin t}\cdot e^{t}dx+C\right] $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,10,0])
        self.play(
            ReplacementTransform(text1,text2)
        )
        self.wait(0.2)
        text3 = Tex(r"$y\left( x+2\pi \right) =e^{-\left( x+2\pi \right) }\left[ \int _{0}^{x+2\pi }e^{\sin t+t}dt+C\right]  $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,0,0])
        self.play(Write(text3),self.camera.frame.animate.scale(1).shift(DOWN*5))

        text4 = Tex(r"$y\left( x+2\pi \right) =e^{-\left( x \right) }\left[ \int _{0}^{x+2\pi }e^{\sin t+t-2\pi}dt+C\cdot e^{-2\pi }\right]  $",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-10,0])
        self.play(Write(text4),self.camera.frame.animate.scale(1).shift(DOWN*5))

        text5 = Tex(r"\text{令}$u=t-2\pi $",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4,RIGHT,buff=5)
        self.play(Write(text5))

        text6 = Tex(r"$y\left( x+2\pi \right)=e^{-x}[ \int _{0}^{x}e^{\sin u+u}du +\int _{-2\pi }^{0}e^{\sin u+n}du+C\cdot e^{-2\pi }] $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-20,0])
        self.play(Write(text6),self.camera.frame.animate.scale(1).shift(DOWN*5))
        text7 = Tex(r"$y\left( x+2\pi \right)=e^{-x}[ \int _{0}^{x}e^{\sin u+u}du +C+\int _{-2\pi }^{0}e^{\sin u+n}du+C\cdot \left( e^{-2\pi }-1\right) ] $",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-20,0])
        self.play(
            ReplacementTransform(text6,text7)
        )
        self.wait(0.2)
        text8 = Tex(r"$y\left( x+2\pi \right)=y\left( x\right) +e^{-x}\left[   \int _{-2\pi }^{0}e^{\sin u+n}du+C\cdot \left( e^{-2\pi }-1\right)\right]  $",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-30,0])
        self.play(Write(text8),self.camera.frame.animate.scale(1).shift(DOWN*5))

        text9 = Tex(r"\text{令}$\int _{-2\pi }^{0}e^{\sin u+n}du+C\cdot \left( e^{-2\pi }-1\right)=0\Rightarrow C=\dfrac{\int ^{0}_{-2\pi }e^{\sin u+u}du}{1-e^{-2\pi }}$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-40,0])
        self.play(Write(text9),self.camera.frame.animate.scale(1).shift(DOWN*5))
        text10 = Tex(r"\text{当且仅当}$\Rightarrow C=\dfrac{\int ^{0}_{-2\pi }e^{\sin u+u}du}{1-e^{-2\pi }}$\text{时,方程存在唯一的以}$2\pi $\text{为周期的解}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-50,0])
        self.play(Write(text10),self.camera.frame.animate.scale(1).shift(DOWN*5))
        self.play(self.camera.frame.animate.scale(1.5).move_to([0,-15,0]))
        self.wait(2)